﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "GbmpModel.h"
#include "IParameterOverride.h"
#include "IParameterValidator.h"
#include "NdbObjectSchematic.h"
#include "DbDataSchema.h"
#include "UniIdentity.h"

namespace gcmp
{
    class NewLevelParameterValidator : public NdbObjectSchematic, public IParameterValidator
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, NewLevelParameterValidator, gcmp::NdbObjectSchematic, C861063B - 772B - 4350 - B32E - 92092C2F1D64, gbmpmodel, gcmp::IParameterValidator)
        DBOBJECT_DATA_END

    public:
        virtual OwnerPtr<IParameterValidator> Clone() const override;
        virtual bool Validate(const IParameter* pNewParameter, const IElement* pElement, std::wstring* pErrorMessage = nullptr) const override;

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }

    private:
        bool ValidateName(const IElement* pElement, const std::wstring& newName, std::wstring* pErrorMessage) const;
    };

    class NewLevelParameterValidatorOverride : public NdbObjectSchematic, public IParameterOverride
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, NewLevelParameterValidatorOverride, gcmp::NdbObjectSchematic, 7180E446 - 0380 - 42EB - 8708 - CD55F1818D53, gbmpmodel, gcmp::IParameterOverride)
            DATA(UniIdentity, ParameterUid)
        DBOBJECT_DATA_END

    public:
        NewLevelParameterValidatorOverride(UniIdentity parameterUid);
        virtual UniIdentity GetUniIdentity() const override;

        virtual bool ShouldOverrideIsModifiable() const override;
        virtual bool IsModifiable() const override;

        virtual bool ShouldOverrideIsUserVisible() const override;
        virtual bool IsUserVisible() const override;

        virtual bool ShouldOverrideGetName() const override;
        virtual std::wstring GetName() const override;

        virtual bool ShouldOverrideGetValidator() const override;
        virtual const IParameterValidator* GetValidator() const override;

        virtual IElement* GetOwnerElement() override { return nullptr; }
        virtual const IElement* GetOwnerElement() const override { return nullptr; }
        virtual bool SetOwnerElement(IElement* pElement) override { return true; }
    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;//
        }
    };
}
